//房源panal
var gridStore = null;
var gridStore2 = null;
var gridStore3 = null;
var gridStore4 = null;
var houseTypeIdStore = null;
var premisesIdStore = null;
var rqTheirMotivesStore = null;
var rqFocusIdStore = null;
var rqDemandFloorStore = null;
var rqServicesIdStore = null;
var rqLifeSupportStore = null;
var rqCourtyardFunctionStore = null;
var familyJieStore = null;
var ftContactWayStore = null;
var peFrameBrandIdStore = null;
var peAcademicQualificationsStore = null;
var peActivityTypeStore = null;
var congshihangyeStore = null;
var companyXingzhiStore = null;
var riChangXinXiStore = null;
var reCurrentlyPropertyStore = null;
var reCurrentlyHouseStore = null;
var reCurrentlyStructureStore = null;
var coWeekendInformationStore = null;
var peDocumentTypeStore = null;
var documentTypeStore = null;
var roomIdStore = null;

var DCouple = "cbstore,customerName,customerSex,customerPhone,customerStatus,informedWay,customerOrigin,ftContactWay,ftContactTimes,ftContactContent";
// var CCouple = DCouple.concat(",rqDemandArea,rqPaymentMethod,peContactAddress,familyJie,congshihangye,companyXingzhi,companyYingye,peActivityType,peResidenceProvinceId,peWorkaroundProvinceId,rqFocusId,peWorkaroundAreaId");
var CCouple = DCouple.concat("");
// var BCouple = CCouple.concat(",rqBudgetPrice,peAcademicQualifications,peDocumentNumber,xuqiuhuxingType,peDomicilePlace,reLocalPurchase,reCurrentlyArea,isLaoren,isZinv,rqBudgetSumprice,peHobbyId,peFrameBrandId,pePlot,buyCar,rqServicesId,rqDemandFloor" );
var BCouple = CCouple.concat("" );
var ACouple = BCouple.concat(",rqTheirMotives,rqFocusId,rqDemandArea,rqPaymentMethod,rqServicesId,peResidenceProvinceId,peResidenceCityId,peResidenceAreaId,peWorkaroundProvinceId,peWorkaroundCityId,peWorkaroundAreaId,congshihangye");
var AJCouple = ACouple.concat(",richangxinxi,peDocumentType,peDocumentNumber,peBirth,peDomicilePlace,peContactAddress,peHobbyId,peActivityType");
var levels = ['','A+','A','B','C','D'];
var ALLCouple = [];
function storeMethed(result){
	return new Ext.data.Store({
    	autoDestroy: true,
        fields :["des","no"],
        data : result
});
}

function userOption(type){
    // var jtcy = Ext.getCmp("familyMember");
	var yxfy = Ext.getCmp("fangyuanGridPanel");
    // jtcy.setTitle( jtcy.title.replace("*",""));
    yxfy.setTitle( yxfy.title.replace("*",""));
	if(ALLCouple.length!=0){
		for(var i=0;i<ALLCouple.length;i++){
			var allcObj = Ext.getCmp(ALLCouple[i]);
			if(ALLCouple[i]=="peResidenceCityId" || ALLCouple[i]=="peResidenceAreaId" || ALLCouple[i]=="peWorkaroundCityId" || ALLCouple[i]=="peWorkaroundAreaId" || ALLCouple[i] =="cbstore" || ALLCouple[i] =="customerPhone"){

    		}else{
    			allcObj.setFieldLabel(allcObj.fieldLabel.replace("*",""));
    		}
			//allcObj.allowBlank=true;
			allcObj.blankText='';
		}
	}
	//清楚掉上一次的，保存这一次的.
	ALLCouple = new Array();
	//AJAX加载数据,不让页面加载JS时间过长，导致页面卡死
	var text=[];
	if(type=="1"){
        // jtcy.setTitle("<font style='color:#e90000;'>*</font>" + jtcy.title);
		yxfy.setTitle("<font style='color:#e90000;'>*</font>" + yxfy.title);
		text=AJCouple.split(",");
	}else if(type=="2"){
        // jtcy.setTitle("<font style='color:#e90000;'>*</font>" + jtcy.title);
		yxfy.setTitle("<font style='color:#e90000;'>*</font>" + yxfy.title);
		text=ACouple.split(",");
	}else if(type=="3"){
        // jtcy.setTitle("<font style='color:#e90000;'>*</font>" + jtcy.title);
        //   yxfy.setTitle("<font style='color:#e90000;'>*</font>" + yxfy.title);
		text=BCouple.split(",");
	}else if(type=="4"){
		text=CCouple.split(",");
	}else if(type=="5"){
		text=DCouple.split(",");
	}
	for(var i=0;i<text.length;i++){
    	var ajObj = Ext.getCmp(text[i]);
        if(text[i]=="peResidenceCityId" || text[i]=="peResidenceAreaId" || text[i]=="peWorkaroundCityId" || text[i]=="peWorkaroundAreaId" || text[i] =="cbstore" || text[i] =="customerPhone"){
            // console.log(text[i]);
        }else{
			ajObj.setFieldLabel("<font style='color:#e90000;'>*</font>"+ajObj.fieldLabel);
		}
	//	ajObj.allowBlank=false;
	//	ajObj.blankText='不能为空';
		ALLCouple.push(text[i]);
    }
/*	 Ext.Ajax.request({
		    url:contextPath+'/customer/customer/getArrayList?type='+type ,
		    method: 'POST',
		    success: function(response){
		        var text = Ext.decode(response.responseText);
		        for(var i=0;i<text.length;i++){
		        	var ajObj = Ext.getCmp(text[i]);
		    		if(text[i]=="peResidenceCityId" || text[i]=="peResidenceAreaId" || text[i]=="peWorkaroundCityId" || text[i]=="peWorkaroundAreaId" ){
		    			
		    		}else{
		    			ajObj.setFieldLabel("<font style='color:#e90000;'>*</font>"+ajObj.fieldLabel);
		    		}
		    		ajObj.allowBlank=false;
		    		ajObj.blankText='不能为空';
		    		ALLCouple.push(text[i]);
		        }
		    }
      });*/
	
}

//根据客户等级验证 客户信息填写情况
function notBlank(ids){
    var text = ids.split(",");
    for(var i = 0;i < text.length;i++){
        if(Ext.getCmp(text[i]) == null) return false;
        if(Ext.getCmp(text[i]).getValue() == '' || Ext.getCmp(text[i]).getValue() == null){
            return false;
        }
    }
    return true;
}
function realLevel(){
    var type = Ext.getCmp("customerStar").getValue();
	var level = 5;
    // 未选择意向等级
    if(notBlank(DCouple)) level = 5;
    // if(notBlank(CCouple)) level = 4; 意向等级B/C/D所需字段一样，所以有限判断
    // if(notBlank(BCouple)) level = 3;
    if(notBlank(ACouple) &&  gridStore4.getCount()) level = 2;
    if(notBlank(AJCouple) &&  gridStore4.getCount()) level = 1;
    return level;
}
function validUserLevel(){
    var ids = '';
    var type = Ext.getCmp("customerStar").getValue();
    //var type = realLevel();
    switch(type){
        case "5" :
            ids = DCouple;
            break;
        case "4" :
            ids = CCouple;
            break;
        case "3" :
            ids = BCouple;
            break;
        case "2" :
            ids = ACouple;
            break;
        case "1" :
            ids = AJCouple;
            break;

        default:// 未选择意向等级
            return -2
    }
    if(type == '1' || type == '2'){
        var records4=gridStore4.getCount();
        if(records4 <= 0){
        	return -1;//验证不通过
		}
	}
    // //意向等级为 1(A+) 2(A) 3(B)  意向房源  家庭成员 判断
	// if(type == '1' || type == '2' || type == '3'){
	// 	var jtcyNum = gridStore.getCount();//家庭成员
	// 	if(jtcyNum == 0){
	// 		return -1;//验证不通过
	// 	}
	// }
    if(notBlank(ids)){
        type = 0
    }else{
        type = -1;
    }
    return type;
}

//增加客户信息的ajax请求
function add(params,resultJson,resultJson2,resultJson3,resultJson4){
    Ext.getCmp("customerSubmitBtn").setVisible(false);
    Ext.Ajax.request({
        url: contextPath+'/customer/customer/add?gridJson='+resultJson+'&gridJson2='+resultJson2+'&gridJson3='+resultJson3+'&gridJson4='+resultJson4,
        // params:form.getValues(),
		params:params,
        callback: function (options, success, response) {
            if (success) {
                var obj = JSON.parse(response.responseText);
                if(obj.res=="1"){
                    Ext.MessageBox.alert("系统提示","保存成功");
                    setTimeout(function(){
                        location.href=contextPath+'/customer/customer/index?menu=menu_0006_0001';
                        //location.href=contextPath + "/customer/customer/toDetail?customerId="+obj.obj+"&resourcesCode=menu_0006_0001";
                    }, 2000)
//					     							Ext.getCmp("save_button").setVisible(false);
                }else{
                    Ext.getCmp("customerSubmitBtn").setVisible(true);
                    Ext.MessageBox.alert("系统提示",obj.resMsg);
                }
            }else{
                Ext.getCmp("customerSubmitBtn").setVisible(true);
                Ext.MessageBox.alert("系统提示","系统异常!");
            }
        }

    });
}

Ext.onReady(function() {
	Ext.QuickTips.init(); //为组件提供提示信息功能，form的主要提示信息就是客户端验证的错误信息。
	Ext.form.Field.prototype.msgTarget='side'; //提示的方式，枚举值为: 
	houseTypeIdStore = new Ext.data.Store({
    	        fields: ["houseTypeName", "id"],
    	        proxy:{
    	            type:'ajax',
    	            url:contextPath+'/customer/customer/projectHouseTypeList',
    	            reader:{
                        type: 'json', 
                        root: 'root'  //数据
                   }
    	        },autoLoad:false
    });
	premisesIdStore = new Ext.data.Store({
    	        fields: ["groupName", "id"],
    	        proxy:{
    	            type:'ajax',
    	            url:contextPath+'/customer/customer/projectPremisesList',
    	            reader:{
                        type: 'json', 
                        root: 'root'  //数据
                   }
    	        },autoLoad:false
    });
	roomIdStore = new Ext.data.Store({
    	        fields: ["combinedName", "id"],
    	        proxy:{
    	            type:'ajax',
    	            url:contextPath+'/customer/customer/projectRoomList',
    	            reader:{
                        type: 'json', 
                        root: 'root'  //数据
                   }
    	        },autoLoad:false
    });
	 gridStore = Ext.create('Ext.data.Store', {
	    fields: ["memberName","documentType","documentNumber"],
	    //是否在服务端排序 （true的话，在客户端就不能排序）
	    remoteSort: false,
	    proxy: {
	        type: 'ajax',
	        url: contextPath+'/customer/familyMember/findList',
	        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
	            type: 'json', //返回数据类型为json格式
	            root: 'obj'
	        },
	        actionMethods: {read: 'POST'}
	    }
	});
		gridStore2 = Ext.create('Ext.data.Store', {
		    fields: ["memberName","documentType","documentNumber"],
		    //是否在服务端排序 （true的话，在客户端就不能排序）
		    remoteSort: false,
		    proxy: {
		        type: 'ajax',
		        url: contextPath+'/customer/familyMember/findList',
		        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		            type: 'json', //返回数据类型为json格式
		            root: 'obj'
		        },
		        actionMethods: {read: 'POST'}
		    }
		});
		gridStore3 = Ext.create('Ext.data.Store', {
		    fields: ["memberName","documentType","documentNumber"],
		    //是否在服务端排序 （true的话，在客户端就不能排序）
		    remoteSort: false,
		    proxy: {
		        type: 'ajax',
		        url: contextPath+'/customer/familyMember/findList',
		        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		            type: 'json', //返回数据类型为json格式
		            root: 'obj'
		        },
		        actionMethods: {read: 'POST'}
		    }
		});
		gridStore4 = Ext.create('Ext.data.Store', {
			id:'fangyuanGridStore',
		    fields: ["memberName","documentType","documentNumber"],
		    //是否在服务端排序 （true的话，在客户端就不能排序）
		    remoteSort: false,
		    proxy: {
		        type: 'ajax',
		        url: contextPath+'/customer/familyMember/findList',
		        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		            type: 'json', //返回数据类型为json格式
		            root: 'obj'
		        },
		        actionMethods: {read: 'POST'}
		    }
		});
		
});


Ext.define('customer.payDeposit.add.estatePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
/*	    var cbstore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["projectName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/follow/returnProjectName?resourcesCode='+resourcesCode+'&resourcesName=resName_cus_list',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:true
	    });*/

		var sexStoreList = [
		                         {"value":"1","text":"男"},
		                         {"value":"2","text":"女"}
		                         ];
		var sexStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : sexStoreList
		});
		informedWayStore = new Ext.data.Store({
    	        singleton:true,
    	        autoDestroy:true,
    	        fields: ["id", "codeName"],
    	        proxy:{
    	            type:'ajax',
    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
    	            reader:{
                        type: 'json', 
                        root: 'root'  //数据
                   }
    	        },
    	        autoLoad:false
	    });
		
		var recommendedCategoryStoreList = [{"value":"1","text":"分销/中介"},
		                                    {"value":"2","text":"老客户(未成交客户)"},
		                                    {"value":"3","text":"老业主"}];

		var recommendedCategoryStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : recommendedCategoryStoreList
		});
		
		var intentionLevelStoreList = [
		                         {"value":"1","text":"A+"},
		                         {"value":"2","text":"A"},
		                         {"value":"3","text":"B"},
		                         {"value":"4","text":"C"},
		                         {"value":"5","text":"D"}
		                         ];
		var intentionLevelStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : intentionLevelStoreList
		});
		
		var customerStatusStoreList = [
				                         {"value":"1","text":"问询"},
				                         {"value":"2","text":"来访"},
//				                         {"value":"3","text":"认筹"},
//				                         {"value":"4","text":"小定"},
//				                         {"value":"5","text":"认购"},
//				                         {"value":"6","text":"签约"},
				                         {"value":"6","text":"无意向"}
				                         ];
		var customerStatusStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : customerStatusStoreList
		});
		
		customerOriginStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var me=this;
		var row_1={
				xtype: "container",
				fieldDefaults: {
		            labelAlign: 'top',
		            msgTarget: 'side'
			    },
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
	            layout: "hbox",
	            items:[{
	                   minWidth: 200,
						 xtype:'displayfield',
				    	 fieldLabel:'经纪人',
			                renderer:function(val){
			                	return userName;
			                }
					},{
		                   minWidth: 200,
						 xtype:'displayfield',
				    	 fieldLabel:'创建人',
			                renderer:function(val){
			                	return userName;
			                }
					}]
				
	    };
		var row_2={
				id:"isPaydepositTrue",
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
			    border: false,
				layout: 'hbox',items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'cbstore',  
			            store: cbstore,
			            displayField: "projectName",           
			            valueField: "id",  
			             fieldLabel:'<font style="color:#e90000;">*</font>项目名称',
			          //  fieldLabel:'项目名称',
			            width:300,
			            queryMode:'local',
			            typeAhead: true,  
		    			name:'projectId',
			            listeners:{
			            	'change':function(value){
			            		houseTypeIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
				            	});
			            		premisesIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
			            		});
			            		/*roomIdStore.load({
			            			params:{
			            				'projectId':value.lastValue
			            			}
			            		});*/
			            		projectId=value.lastValue;
			            		if(projectId && projectId == "-1"){
				            		projectId="";
				            		Ext.getCmp("cbstore").setValue("");
			            		}
			            		if(projectId != ""){
			            			//获知途径
                                    Ext.getCmp('informedWay').setValue("");
			            			informedWayStore.load({
				            			params:{
				            				'projectId':projectId,
				            				'typeValue':'informedWay'
				            			}
				            		});
			            			//客户性质
                                    Ext.getCmp('customerOrigin').setValue("");
			            			customerOriginStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'customerNature'
				            			}
			            			});
			            			//置业动机
                                    Ext.getCmp('rqTheirMotives').setValue("");
			            			rqTheirMotivesStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'theirMotives'
				            			}
			            			});
			            			//关注重点
                                    Ext.getCmp('rqFocusId').setValue("");
			            			rqFocusIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'focus'
				            			}
			            			});
			            			//需求楼层
                                    Ext.getCmp('rqDemandFloor').setValue("");
			            			rqDemandFloorStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'floor'
				            			}
			            			});
			            			//生活服务
                                    Ext.getCmp('rqServicesId').setValue("");
			            			rqServicesIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'lifeService'
				            			}
			            			});
			            			//生活配套
                                    Ext.getCmp('rqLifeSupport').setValue("");
			            			rqLifeSupportStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'lifeSupport'
				            			}
			            			});
			            			//希望庭院具备功能
                                    Ext.getCmp('rqCourtyardFunction').setValue("");
			            			rqCourtyardFunctionStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'courtyardFunction'
				            			}
			            			});
			            			//家庭结构
                                    Ext.getCmp('familyJie').setValue("");
			            			familyJieStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'familyJie'
				            			}
			            			});
			            			//联系方式
                                    Ext.getCmp('ftContactWay').setValue("");
			            			ftContactWayStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'contactWay'
				            			}
			            			});
			            			//车驾品牌
                                    Ext.getCmp('peFrameBrandId').setValue("");
			            			peFrameBrandIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'frameBrand'
				            			}
			            			});
			            			//乐于参加的活动类型
                                    Ext.getCmp('peActivityType').setValue("");
			            			peActivityTypeStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'activityType'
				            			}
			            			});
			            			//兴趣爱好
                                    Ext.getCmp('peHobbyId').setValue("");
			            			peHobbyIdStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'hobby'
				            			}
			            			});
			            			//学历
                                    Ext.getCmp('peAcademicQualifications').setValue("");
			            			peAcademicQualificationsStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'academicQualifications'
				            			}
			            			});
			            			//从事行业
                                    Ext.getCmp('congshihangye').setValue("");
			            			congshihangyeStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'congshihangye'
				            			}
			            			});
			            			//公司性质
                                    Ext.getCmp('companyXingzhi').setValue("");
			            			companyXingzhiStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'companyXingzhi'
				            			}
			            			});
			            			//日常信息获取途径
                                    Ext.getCmp('richangxinxi').setValue("");
			            			riChangXinXiStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'richangxinxi'
				            			}
			            			});
			            			//目前居住物业类型
                                    Ext.getCmp('reCurrentlyProperty').setValue("");
			            			reCurrentlyPropertyStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'currentlyProperty'
				            			}
			            			});
			            			//目前居住/办公房子属性
                                    Ext.getCmp('reCurrentlyHouse').setValue("");
			            			reCurrentlyHouseStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'currentlyHouse'
				            			}
			            			});
			            			//目前居住户型结构
                                    Ext.getCmp('reCurrentlyStructure').setValue("");
			            			reCurrentlyStructureStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'currentlyStructure'
				            			}
			            			});
			            			//联系方式
                                    Ext.getCmp('coInformationDays').setValue("");
                                    Ext.getCmp('coWeekendInformation').setValue("");
			            			coWeekendInformationStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'contactInformation'
				            			}
			            			});
			            			//证件类型
                                    Ext.getCmp('peDocumentType').setValue("");
			            			peDocumentTypeStore.load({
			            				params:{
				            				'projectId':projectId,
				            				'typeValue':'documentType'
				            			}
			            			});
			            			//证件类型 （家庭成员列表）
                                    documentTypeStore.load({
                                        params:{
                                            'projectId':projectId,
                                            'typeValue':'documentType'
                                        }
                                    });
			            		}
			            	}
			            },
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
	            	},{
		                xtype:'textfield',
		                // fieldLabel: '<font style="color:#e90000;">*</font>客户姓名',
						fieldLabel: '客户姓名',
		                name: 'customerName',
		                allowBlank:true,
		                blankText:'不能为空',
						id:'customerName'
		            }, {
			            xtype:'combobox',  
//			            style: 'position:absolute;left:15px;',  
			            id:'customerSex',  
			            store: sexStore,
			            displayField: "text",           
			            valueField: "value",  
			            // fieldLabel:'<font style="color:#e90000;">*</font>性别',
			            fieldLabel:'性别',
			            typeAhead: true,
		    			name:'customerSex',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
		            }, {
		                xtype:'numberfield',
		                 fieldLabel: '<font style="color:#e90000;">*</font>联系电话',
		                //fieldLabel: '联系电话',
		                name: 'customerPhone',
		                allowBlank:true,
		                blankText:'不能为空',
		                maxLength:11,  
		                hideTrigger:true,
		                id:'customerPhone',
		                regex: /^1[3|4|5|6|7|8|9]\d{9}$/,
			            listeners:{
			            	blur: function(value){
			            		if(value.lastValue){
			            			var projectId = Ext.getCmp('cbstore').getValue();
			            			Ext.Ajax.request({
			            				url: contextPath+'/customer/customer/customerPhone',
			            				params: {
			            					phone: value.lastValue,
			            					projectId:projectId
			            				},
			            				method: 'POST',
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.res=="1"){
			            						Ext.MessageBox.alert('提示', '该手机号码已存在!');
			            					}else if(text.res=="10000"){
			            						Ext.MessageBox.alert("系统提示","系统异常!");
			            					}
			            				}
			            			});
			            		}
			                }
			            }
		             
		            }, {
			            xtype:'combobox',  
		                // fieldLabel: '<font style="color:#e90000;">*</font>获知途径',
		                fieldLabel: '获知途径',
		                name: 'informedWay',
			            store: informedWayStore,
		                id: 'informedWay',
			            displayField: "codeName",           
			            valueField: "id",
			            listeners:{
			            	'change':function(value){
			            		var displayValue = Ext.getCmp('informedWay').getRawValue();
			            		//为全员营销或者外部推荐时，展示推荐人信息
			            		if(displayValue == "全员营销"|| displayValue == "外部推荐时"){
			            			Ext.getCmp('recommendedCategory').show();
			            			Ext.getCmp('recommendedName').show();
			            			Ext.getCmp('recommendedMobile').show();
			            			Ext.getCmp('recommendedUnit').show();
			            		}else{
			            			Ext.getCmp('recommendedCategory').hide();
			            			Ext.getCmp('recommendedName').hide();
			            			Ext.getCmp('recommendedMobile').hide();
			            			Ext.getCmp('recommendedUnit').hide();
			            		}
			            	}
			            },
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
		                xtype:'textfield',
		                fieldLabel: '推荐人姓名',
		                name: 'recommendedName',
		                id: 'recommendedName',
		                hidden:true
		            }, {
		                xtype:'textfield',
		                fieldLabel: '推荐人单位',
		                name: 'recommendedUnit',
		                id: 'recommendedUnit',
		                hidden:true
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'customerStar',  
			            store: intentionLevelStore,
			            displayField: "text",           
			            valueField: "value",  
			            // fieldLabel:'<font style="color:#e90000;">*</font>意向等级',
			            fieldLabel:'意向等级',
			            typeAhead: true,
		    			name:'intentionLevel',
		                allowBlank:true,
		                blankText:'不能为空',
		                listeners:{
			            	'change':function(value){
			            		if(value.lastValue=="1"){
			            			userOption('1');
			            		}else if(value.lastValue=="2"){
			            			userOption('2');
			            		}else if(value.lastValue=="3"){
			            			userOption('3');
			            		}else if(value.lastValue=="4"){
			            			userOption('4');
			            		}else if(value.lastValue=="5"){
			            			userOption('5');
			            		}
			            	}
			            },
		                typeAhead:false, 
		                editable:false
		            },{
			            xtype:'combobox',  
			            id:'customerStatus',  
			            store: customerStatusStore,
			            displayField: "text",           
			            valueField: "value",  
			            // fieldLabel:'<font style="color:#e90000;">*</font>客户状态',
			            fieldLabel:'客户状态',
			            typeAhead: true,
		    			name:'customerStatus',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false
		            },{
			            xtype:'combobox',  
			            id:'customerOrigin',  
			            store: customerOriginStore,
			            displayField: "codeName",           
			            valueField: "id",  
						fieldLabel:'客户性质',
			            // fieldLabel:'<font style="color:#e90000;">*</font>客户性质',
		    			name:'customerOrigin',
		                allowBlank:true,
		                blankText:'不能为空',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
			            xtype:'combobox',  
		                fieldLabel: '推荐人类别',
		                id:'recommendedCategory',
		                name: 'recommendedCategory',
			            store: recommendedCategoryStore,
			            displayField: "text",           
			            valueField: "value",
		                hidden:true,
		                typeAhead:false, 
		                editable:false
		            }, {
		                xtype:'numberfield',
		                fieldLabel: '推荐人手机',
		                name: 'recommendedMobile',
		                id:'recommendedMobile',
		                hidden:true,
		                blankText:'不能为空',
		                maxLength:11,  
		                hideTrigger:true,
		                regex: /^1[3|4|5|6|7|8|9]\d{9}$/,
		                listeners:{
			            	blur: function(value){
			            		if(value.lastValue){
			            			//在验证手机号码是否正确
			            			Ext.Ajax.request({
			            				url: contextPath+'/common/mobile/verifyingMobile',
			            				params: {
			            					mobile: value.lastValue,
			            				},
			            				method: 'POST',
			            				async: false,
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.result=="1"){
			            						if(text.flag != "1"){
			            							Ext.MessageBox.alert('提示', '请输入正确的手机号码');
			            						}
			            					}
			            				}
			            			});
			            		}
			            	}
		                }
		            },{
		                xtype:'textfield',
		                fieldLabel: 'ID',
		                name: 'id',
		                id:'customerId',
		                hidden:true
		            }]
		        }]
	    };
		var items=[row_1,row_2];
		var initConfigg = {
				title:"客户基本信息",
				bodyStyle: 'padding:5px 5px 0',
		        minHeight: 100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.add.customerPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		rqFocusIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    
	    rqServicesIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    
		rqTheirMotivesStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var rqDemandAreaStoreList = [
				                         {"value":"1","text":"50㎡以下"},
				                         {"value":"2","text":"50-70㎡"},
				                         {"value":"3","text":"70-90㎡"},
				                         {"value":"4","text":"90-120㎡"},
				                         {"value":"5","text":"120-140㎡"},
				                         {"value":"6","text":"140-160㎡"},
				                         {"value":"7","text":"160-180㎡"},
				                         {"value":"8","text":"180-200㎡"},
				                         {"value":"9","text":"200㎡以上"}
				                         ];
		var rqDemandAreaStore = Ext.data.Store({
		    	autoDestroy: true,
		        fields :["value","text"],
		        data : rqDemandAreaStoreList
		});
		rqDemandFloorStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		rqLifeSupportStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		rqCourtyardFunctionStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		var rqBudgetPriceStoreList = [
					                         {"value":"1","text":"5000元/㎡以下"},
					                         {"value":"2","text":"5000-5500元/㎡"},
					                         {"value":"3","text":"5500-6000元/㎡"},
					                         {"value":"4","text":"6000-8000元/㎡"},
					                         {"value":"5","text":"8000-10000元/㎡"},
					                         {"value":"6","text":"10000-12000元/㎡"},
					                         {"value":"7","text":"12000-14000元/㎡"},
					                         {"value":"8","text":"14000-16000元/㎡"},
					                         {"value":"9","text":"16000-18000元/㎡"},
					                         {"value":"10","text":"18000-20000元/㎡"},
					                         {"value":"11","text":"20000-22000元/㎡"},
					                         {"value":"12","text":"22000-25000元/㎡"},
					                         {"value":"13","text":"25000-28000元/㎡"},
					                         {"value":"14","text":"28000-30000元/㎡"},
					                         {"value":"15","text":"30000元/㎡以上"}
					                         ];
		var rqBudgetPriceStore = Ext.data.Store({
			    autoDestroy: true,
			    fields :["value","text"],
			    data : rqBudgetPriceStoreList
		});
		var rqBudgetSumpriceStoreList = [
				                         {"value":"1","text":"50万元以下"},
				                         {"value":"2","text":"50-80万元"},
				                         {"value":"3","text":"80-100万元"},
				                         {"value":"4","text":"100-150万元"},
				                         {"value":"5","text":"150-200万元"},
				                         {"value":"6","text":"200-250万元"},
				                         {"value":"7","text":"250-300万元"},
				                         {"value":"8","text":"300-400万元"},
				                         {"value":"9","text":"400-500万元"},
				                         {"value":"10","text":"500-600万元"},
				                         {"value":"11","text":"600-800万元"},
				                         {"value":"12","text":"800-1000万元"},
				                         {"value":"13","text":"1000万元以上"}
				                         ];
		
		var rqBudgetSumpriceStore = Ext.data.Store({
			    autoDestroy: true,
			    fields :["value","text"],
			    data : rqBudgetSumpriceStoreList
		});
		
		familyJieStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var me=this;
		var row_1={
				fieldDefaults: {
			            labelAlign: 'top',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'rqTheirMotives',  
			            store: rqTheirMotivesStore,
			            displayField: "codeName",           
			            valueField: "id", 
			            fieldLabel:'置业动机',
			            typeAhead: true,
		    			name:'rqTheirMotives',
		                /*allowBlank:false,
		                blankText:'不能为空',*/
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
			            xtype:'combobox',  
			            id:'rqDemandArea',  
			            store: rqDemandAreaStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'需求面积',
			            typeAhead: true,
		    			name:'rqDemandArea',
		                typeAhead:false, 
		                editable:false
		            }, {
			            xtype:'combobox',  
			            id:'rqServicesId',  
			            store: rqServicesIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'生活服务',
		    			name:'rqServicesId',
		                typeAhead:false, 
		                editable:false,
		                triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            }, {
			            xtype:'combobox',  
			            id:'rqBudgetSumprice',  
			            store: rqBudgetSumpriceStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'预算总价',
			            typeAhead: true,
		    			name:'rqBudgetSumprice',
		                typeAhead:false, 
		                editable:false
		            },{
			            xtype:'combobox',  
			            id:'rqCourtyardFunction',  
			            store: rqCourtyardFunctionStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'希望庭院具备功能',
			            typeAhead: true,
		    			name:'rqCourtyardFunction',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            },{
		            	xtype:'combobox',  
			            fieldLabel:'付款方式',  
			            typeAhead: true,
		    			name:'rqPaymentMethod',
		    			displayField: "des",           
				        valueField: "no", 
				        id:'rqPaymentMethod',
				        store:storeMethed(paymentMethod),
		                typeAhead:false, 
		                editable:false
		            },{
		            	xtype:'combobox',  
			            fieldLabel:'购买车位',  
			            typeAhead: true,
		    			name:'buyCar',
		    			id:'buyCar',
		    			displayField: "des",           
				        valueField: "no",  
				        store:storeMethed(buyCarEnum),
		                typeAhead:false, 
		                editable:false
		            	
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'rqFocusId',  
			            store: rqFocusIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'关注重点',
		    			name:'rqFocusId',
		    			triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            },{
			            xtype:'combobox',  
			            id:'rqDemandFloor',  
			            store: rqDemandFloorStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'需求楼层',
		    			name:'rqDemandFloor',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            },{
			            xtype:'combobox',  
			            id:'rqLifeSupport',  
			            store: rqLifeSupportStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'生活配套',
		    			name:'rqLifeSupport',
		                typeAhead:false, 
		                editable:false,
		            	triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            },{
			            xtype:'combobox',  
			            id:'rqBudgetPrice',  
			            store: rqBudgetPriceStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'预算单价',
		    			name:'rqBudgetPrice',
		                typeAhead:false, 
		                editable:false
		            },{
		                xtype:'numberfield',
		                fieldLabel: '庭院需求面积',
		                name: 'rqCourtyardArea',
		                hideTrigger:true,
		                maxLength:4
		            },{
		            	xtype:'combobox',
			            fieldLabel: '家庭结构',
			            name: 'familyJie',
			            displayField: "codeName",           
				        valueField: "id",  
				        id:'familyJie',
				        store:familyJieStore,
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            },{
		            	xtype:'combobox',
			            fieldLabel: '需求户型规格',
			            name: 'xuqiuhuxingType',
						id:'xuqiuhuxingType',
			            displayField: "des",           
				        valueField: "no",  
				        store:storeMethed(xuQiuHuXingEnum),
		                typeAhead:false, 
		                editable:false
		            	
		            }]
		        }]
	    };
		var columns = [{
			text : "户型",
			dataIndex : 'houseTypeId',
			width:'50%',
			editor: {
		            xtype:'combobox',  
		            id:'houseTypeId',  
		            displayField: "houseTypeName",           
		            valueField: "id",
		            name:'houseTypeId',
		            store: houseTypeIdStore,
		            queryMode:'local',
	                typeAhead:false, 
	                editable:false
            },  
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
            	 var index = houseTypeIdStore.find('id',value);  
                 if(index!=-1){  
                     return houseTypeIdStore.getAt(index).data.houseTypeName;  
                 }  
                 return value; 
            }
		},{
        	text:'操作',
        	xtype : 'actioncolumn',
        	width:'40%',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore2.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_2=Ext.create('Ext.grid.Panel', {
			id:'huxingGridPanel',
			title:'关注户型',
			minHeight:100,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore2,
			columns : columns,
			plugins: [cellEditing],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore2.insert(0, record);
				    cellEditing.startEditByPosition({
				        row: 0, 
				    	column: 0
				    });
			}
			}
			]
		});
		var columns3 = [{
			text : "团名",
			dataIndex : 'premisesId',
			width:'50%',
			editor: {
	            xtype:'combobox',  
	            id:'premisesId',  
	            store: premisesIdStore,
	            displayField: "groupName",
	            valueField: "id",
	            name:'premisesId',
	            queryMode:'local',
                typeAhead:false, 
                editable:false,
                listeners:{
	            	'change':function(value){
	            		roomIdStore.load({
	            			params:{
	            				'projectId':projectId,
	            				'premisesId':value.lastValue
	            			}
	            		});
	            	}
	            }
            },  
            renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
            	var index = premisesIdStore.find('id',value);  
                if(index!=-1){  
                    return premisesIdStore.getAt(index).data.groupName;  
                }  
                return value; 
            }
		},{
        	text:'操作',
        	xtype : 'actioncolumn',
        	width:'40%',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore3.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing3 = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_3=Ext.create('Ext.grid.Panel', {
			id:'yixiangGridPanel',
			title:"意向组团",
			minHeight:100,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore3,
			columns : columns3,
			plugins: [cellEditing3],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore3.insert(0, record);
				    cellEditing3.startEditByPosition({
				        row: 0, 
				    	column: 0
				    });
			}
			}
			]
		});
		var columns4 = [{
			text : "房间",
			dataIndex : 'roomId',
			width:'50%',
			editor: {
	            xtype:'combobox',  
	            id:'roomId',  
	            store: roomIdStore,
	            displayField: "combinedName",
	            valueField: "id",
	            name:'roomId',
	            queryMode:'local',
                typeAhead:false, 
                editable:false  
            },
		 renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
         	 var index = roomIdStore.find('id',value);  
             if(index!=-1){  
                 return roomIdStore.getAt(index).data.combinedName;  
             }  
             return value; 
         }
		},{
        	text:'操作',
        	xtype : 'actioncolumn',
        	width:'40%',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore4.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing4 = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_4=Ext.create('Ext.grid.Panel', {
			id:'fangyuanGridPanel',
			title:"意向房源",
			minHeight:100,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore4,
			columns : columns4,
			plugins: [cellEditing4],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore4.insert(0, record);
				    cellEditing4.startEditByPosition({
				        row: 0, 
				    	column: 0
				    });
			}
			}
			]
		});
		var row_5={
				defaults: {
		            border: false,
		            xtype: 'panel',
		            flex: 1
		        },
			    border: false,
				layout: 'hbox',
				items: [{
					items:row_2
				},{
					items:row_3
				}, {
					items:row_4
				}]
	    };
		var items=[row_1,row_5];//,row_2,row_3,row_4
		var initConfigg = {
		        title:"客户购房需求",
		        minHeight:320,
		        bodyStyle: 'padding:5px 5px 0',
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        scrollable:true,
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.add.firstjiePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		ftContactWayStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'column',   
				items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'ftContactWay',  
			            store: ftContactWayStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            // fieldLabel:'<font style="color:#e90000;">*</font>接触方式',
			            fieldLabel:'接触方式',
			            typeAhead: true,
		    			name:'ftContactWay',
		                typeAhead:false, 
		                editable:false,
		                allowBlank:true,
			            blankText:'不能为空',
			            queryMode:'local'
		            }, {
		                xtype:'datefield',
		                // fieldLabel: '<font style="color:#e90000;">*</font>接触时间',
		                fieldLabel: '接触时间',
		                name: 'ftContactTimes',
		                id:'ftContactTimes',
		                format: 'Y-m-d',
		                allowBlank:true,
			            blankText:'不能为空',
						editable:false,
                        readOnly:true
                    }, {
		                xtype:'textarea',
		                fieldLabel: '沟通内容',
		                //fieldLabel: '<font style="color:#e90000;">*</font>沟通内容',
		                anchor: '80%',
		                name:'ftContactContent',
		                id:'ftContactContent',
		                minWidth:1100,
		                allowBlank:true,
			            blankText:'不能为空'
		            }]
		        }
//				, {
//		            items: []
//		        }
				]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"首次接触信息",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.payDeposit.add.membergePanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
	    peFrameBrandIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    peHobbyIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		peDocumentTypeStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var peDomicilePlaceStoreList = [
				                         {"value":"1","text":"本地"},
				                         {"value":"2","text":"省外"},
				                         {"value":"3","text":"省内"},
				                         {"value":"4","text":"境外"}
				                         ];
		var peDomicilePlaceStore = Ext.data.Store({
				autoDestroy: true,
				fields :["value","text"],
				data : peDomicilePlaceStoreList
		});
		var peHouseholdIncomeStoreList = [
				                         {"value":"1","text":"20万元以下"},
				                         {"value":"2","text":"20-30万元"},
				                         {"value":"3","text":"30-50万元"},
				                         {"value":"4","text":"50-80万元"},
				                         {"value":"5","text":"80-100万元"},
				                         {"value":"6","text":"100-200万元"},
				                         {"value":"7","text":"200-300万元"},
				                         {"value":"8","text":"300-500万元"},
				                         {"value":"9","text":"500万元以上"}
				                         ];
		var peHouseholdIncomeStore = Ext.data.Store({
				autoDestroy: true,
				fields :["value","text"],
				data : peHouseholdIncomeStoreList
		});
		peActivityTypeStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		//省份
	    var peResidenceProvinceIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/provList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:true
	    });
	    //工作省
	    var peWorkaroundProvinceIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/provList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:true
	    });
	    //城市
	    var peResidenceCityIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/cityList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //区域
	    var peResidenceAreaIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/areaList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //工作城市
	    var peWorkaroundCityIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/cityList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    //工作区域
	    var peWorkaroundAreaIdStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["areaName", "id"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/customer/customer/areaList',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        }
	    });
	    
	    riChangXinXiStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
	    
	    peAcademicQualificationsStore= new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
        });
	    
	    congshihangyeStore= new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
        });
	    
	    companyXingzhiStore= new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
        });
	    
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'peDocumentType',  
			            store: peDocumentTypeStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'证件类型',
			            typeAhead: true,
		    			name:'peDocumentType',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
		                xtype:'textfield',
		                fieldLabel: '证件号码',
		                width:300,
		                name: 'peDocumentNumber',
		                id:'peDocumentNumber',
		                regex: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
		            }, {
		                xtype:'datefield',
		                fieldLabel: '出生日期',
		                name: 'peBirth',
		                format: 'Y-m-d',
		                id:'peBirth'
		            }, {
		                xtype:'textfield',
		                fieldLabel: '年龄',
		                name: 'peAge',
		                id:'peAge',
		                maxLength:3,
			             regex:/^[1-9]\d*$/
		            }, {
		                xtype:'textfield',
		                fieldLabel: '固定电话',
		                name: 'peTelephone',
			                maxLength:11,
			                regex:/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
		            }, {
		                xtype:'textfield',
		                fieldLabel: '手机号码',
		                name: 'peMobile',
		                id:'peMobile',
		                maxLength:11,  
		                regex: /^1[3|4|5|6|7|8|9]\d{9}$/,
		                listeners:{
			            	blur: function(value){
			            		if(value.lastValue){
			            			var projectId = Ext.getCmp('cbstore').getValue();
			            			Ext.Ajax.request({
			            				url: contextPath+'/customer/customer/customerPhone',
			            				params: {
			            					phone: value.lastValue,
			            					projectId:projectId
			            				},
			            				method: 'POST',
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.res=="1"){
			            						Ext.MessageBox.alert('提示', '该手机号码已存在!');
			            					}else if(text.res=="10000"){
			            						Ext.MessageBox.alert("系统提示","系统异常!");
			            					}
			            				}
			            			});
			            		}
			                }
			            }
		            }, {
		                xtype:'textfield',
		                fieldLabel: '邮箱',
		                name: 'peEmail',  
		                vtype:'email'
		            }, {
		                xtype:'textfield',
		                fieldLabel: '微信',
		                name: 'peWechat'
		            }, {
			            xtype:'combobox',  
			            id:'peFrameBrandId',  
			            store: peFrameBrandIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'车驾品牌',
			            typeAhead: true,
		    			name:'peFrameBrandId',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
			            xtype:'combobox',  
			            id:'peActivityType',  
			            store: peActivityTypeStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'乐于参加的活动类型', 
		    			name:'peActivityType',
		                typeAhead:false, 
		                editable:false,
		                triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            },{
		            	 xtype:'textfield',
			             fieldLabel: '邮编',
			             name: 'pePostcode',
			                maxLength:6,
				             regex:/^[1-9]\d*$/
		            },{
		            	 xtype:'combobox',
			             fieldLabel: '学历',
			             name:'peAcademicQualifications',
			             id:'peAcademicQualifications',
			         	 displayField: "codeName",           
				         valueField: "id",  
				         store:peAcademicQualificationsStore,
			             typeAhead:false, 
			             editable:false,
			             queryMode:'local'
		            },{
		            	 xtype:'combobox',
			             fieldLabel: '从事行业',
			             name: 'congshihangye',
			             id:'congshihangye',
			             displayField: "codeName",           
				         valueField: "id",  
				         store:congshihangyeStore,
			             typeAhead:false, 
			             editable:false,
			             queryMode:'local'
		            },{
		            	 xtype:'combobox',
			             fieldLabel: '公司性质',
			             name: 'companyXingzhi',
			             displayField: "codeName",           
				         valueField: "id",  
				         store:companyXingzhiStore,
				         id:'companyXingzhi',
			             typeAhead:false, 
			             editable:false,
			             queryMode:'local'
		            },{
		            	xtype:'textfield',
			             fieldLabel: '公司年营业额',
			             name: 'companyYingye',
		            	id:'companyYingye',
		                maxLength:11
		            },{
		            	 xtype:'combobox',
			             fieldLabel: '是否员工',
			             name: 'isYuangong',
			             displayField: "des",           
					     valueField: "no",  
					     store:storeMethed(isAvlidEnum),
			                typeAhead:false, 
			                editable:false
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'peDomicilePlace',  
			            store: peDomicilePlaceStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'户籍所在地',
			            typeAhead: true,
		    			name:'peDomicilePlace',
		    			id:'peDomicilePlace',
		                typeAhead:false, 
		                editable:false
		            }, {
		                xtype:'textfield',
		                fieldLabel: '联系地址',
		                name: 'peContactAddress',
		                id:'peContactAddress'
		            }, {
		            	items: [{
							xtype : "panel",
							layout : "hbox",
							border:false,
							items : [{
					            xtype:'combobox',  
					            id:'peResidenceProvinceId',  
					            store: peResidenceProvinceIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            fieldLabel:'居住地',
				    			name:'peResidenceProvinceId' ,
					            typeAhead: true,
					            width:200,
					            listeners:{
					            	'select':function(value){
					            		Ext.getCmp('peResidenceCityId').setValue("");
					            		Ext.getCmp('peResidenceAreaId').setValue("");
						            		peResidenceCityIdStore.load({
						            			params:{
						            				'id':value.lastValue
						            			}
						            		});
					            	}
					            },
					            /*allowBlank:false,
					            blankText:'不能为空',*/
				                typeAhead:false, 
				                editable:false
				            },{
					            xtype:'combobox',  
					            id:'peResidenceCityId',  
					            store: peResidenceCityIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            width:100,
					           // fieldLabel:'居住市',
				    			name:'peResidenceCityId' ,
					            typeAhead: true,
					            listeners:{
					            	'select':function(value){
					            		Ext.getCmp('peResidenceAreaId').setValue("");
					            			peResidenceAreaIdStore.load({
					            				params:{
					            					'id':value.lastValue
					            				}
					            			});
					            	}
					            },
				    			queryMode : 'local',
								/*allowBlank:false,
					            blankText:'不能为空',*/
				                typeAhead:false, 
				                editable:false
				            },{
					            xtype:'combobox',  
					            id:'peResidenceAreaId',  
					            store: peResidenceAreaIdStore,
					            displayField: "areaName",           
					            valueField: "id",  
					            width:100,
					            //fieldLabel:'居住区',
					            typeAhead: true,
				    			name:'peResidenceAreaId',
				    			queryMode : 'local',
								/*allowBlank:false,
					            blankText:'不能为空',*/
				                typeAhead:false, 
				                editable:false
				            }]
						}]
		            }, {
		                xtype:'textfield',
		                fieldLabel: '小区',
		                name: 'pePlot',
		                id: 'pePlot'
		            }, {
		                xtype:'textfield',
		                fieldLabel: '详细地址',
		                name: 'peDetailedAddress'
		            }, {
		            	items: [{
		            		xtype : "container",
							layout : "hbox",
							items : [
								{
								    xtype:'combobox',  
								    id:'peWorkaroundProvinceId',  
								    store: peWorkaroundProvinceIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:200,
								    fieldLabel:'工作区',
								    typeAhead: true,
								    listeners:{
								    	'select':function(value){
								    		Ext.getCmp('peWorkaroundCityId').setValue("");
								    		Ext.getCmp('peWorkaroundAreaId').setValue("");
								        		peWorkaroundCityIdStore.load({
								        			params:{
								        				'id':value.lastValue
								        			}
								        		});
								    	}
								    },
									name:'peWorkaroundProvinceId',
									/*allowBlank:false,
						            blankText:'不能为空',*/
					                typeAhead:false, 
					                editable:false
								},{
								    xtype:'combobox',  
								    id:'peWorkaroundCityId',  
								    store: peWorkaroundCityIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:100,
								    typeAhead: true,
								    listeners:{
								    	'select':function(value){
								    		Ext.getCmp('peWorkaroundAreaId').setValue("");
								        		peWorkaroundAreaIdStore.load({
								        			params:{
								        				'id':value.lastValue
								        			}
								        		});
								    	}
								    },
									name:'peWorkaroundCityId',
									queryMode : 'local',
									/*allowBlank:false,
						            blankText:'不能为空',*/
					                typeAhead:false, 
					                editable:false
								},{
								    xtype:'combobox',  
								    id:'peWorkaroundAreaId',  
								    store: peWorkaroundAreaIdStore,
								    displayField: "areaName",           
								    valueField: "id",  
								    width:100,
								    typeAhead: true,
									name:'peWorkaroundAreaId',
									queryMode : 'local',
									/*allowBlank:false,
						            blankText:'不能为空',*/
					                typeAhead:false, 
					                editable:false
								}
							]
		            	}]
		            }, {
		                xtype:'textfield',
		                fieldLabel: '详细地址',
		                name: 'peWorkaroundAddress'
		            }, {
			            xtype:'combobox',  
			            id:'peHouseholdIncome',  
			            store: peHouseholdIncomeStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'家庭年收入',
			            typeAhead: true,
		    			name:'peHouseholdIncome',
		                typeAhead:false, 
		                editable:false
		            }, {
			            xtype:'combobox',  
			            id:'peHobbyId',  
			            store: peHobbyIdStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'兴趣爱好',  
			            listeners:{
			            	'select':function(value){
			            	}
			            },
		    			name:'peHobbyId',
		                typeAhead:false, 
		                editable:false,
		                triggerAction : 'all',
		                multiSelect : true,
		                queryMode:'local'
		            },{
		            	 xtype:'combobox',
			             fieldLabel: '是否有子女',
			             name: 'isZinv',
			             id:'isZinv',
			             displayField: "des",           
					     valueField: "no",  
					     store:storeMethed(isAvlidEnum),
			                typeAhead:false, 
			                editable:false
	            },{
	            	 xtype:'combobox',  
			         displayField: "text",           
			         fieldLabel:'是否与老人同住',  
		    		 name:'isLaoren',
		    		 id:'isLaoren',
		    		 displayField: "des",           
				     valueField: "no",  
				     store:storeMethed(isAvlidEnum),
		                typeAhead:false, 
		                editable:false
	            },{
			            	 xtype:'textfield',
				             fieldLabel: 'QQ号码',
				             name: 'qqNumber',
				             regex:/^[1-9]\d*$/,  
				                maxLength:12
		            },{
		            	 xtype:'combobox',  
				         displayField: "text",           
				         fieldLabel:'是否本公司业主',  
			    		 name:'isYezhu',
			    		 displayField: "des",           
					     valueField: "no",  
					     store:storeMethed(isOwnerCompanyEnum),
			                typeAhead:false, 
			                editable:false
		            },{
		            	 xtype:'combobox',  
				         displayField: "text",           
				         fieldLabel:'日常信息获取途径',  
			    		 name:'richangxinxi',
			    		 id:'richangxinxi',
			    		 displayField: "codeName",           
					     valueField: "id",  
					     store: riChangXinXiStore,
			        	 typeAhead:false, 
			         	 editable:false,
			         	 triggerAction : 'all',
		                 multiSelect : true,
		                 queryMode:'local'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"客户个人信息",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.payDeposit.add.jiatingPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var me=this;
		documentTypeStore = new Ext.data.Store({
    	        singleton:true,
    	        autoDestroy:true,
    	        fields: ["id", "codeName"],
    	        proxy:{
    	            type:'ajax',
    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
    	            reader:{
                        type: 'json', 
                        root: 'root'  //数据
                   }
    	        },
    	        autoLoad:true
	    });


		var columns = [{
			text : "姓名",
			dataIndex : 'memberName',
			width:'10%',
			editor: {
                xtype: 'textfield'
            }
		}, {
			text : "证件类型",
			dataIndex : 'documentType',
			width:'10%',
			editor: new Ext.form.field.ComboBox({
			    store: documentTypeStore,
			    queryMode: 'local',
			    displayField: 'codeName',
			    valueField: 'id',
                typeAhead:false, 
                editable:false
            }),
            renderer:function(value,metadata,record){
            	if(value){
            		var index = documentTypeStore.find('id',value);
                    if(index!=-1){  
                        return documentTypeStore.getAt(index).data.codeName;  
                    }  
                    return value;
            	}
            }
		}, {
			text : "证件号码",
			dataIndex : 'documentNumber',
			width:'10%',
			editor: {
                xtype: 'textfield',
                maxLength:18
            }
		}, {
			text : "生日",
			dataIndex : 'birthday',
			width:'10%',
			editor: {
                xtype: 'datefield',
                format: 'Y-m-d'
            },
            renderer:function(value){
            	if(value)
            	return Ext.Date.format(new Date(value),'Y-m-d')
            }
		}, {
			text : "结婚纪念日",
			dataIndex : 'marryday',
			width:'10%',
			editor: {
                xtype: 'datefield',
                format: 'Y-m-d'
            },
            renderer:function(value){
            	if(value)
            	return Ext.Date.format(new Date(value),'Y-m-d')
            }
		}, {
        	text:'操作',
        	xtype : 'actioncolumn',
        	items:[{
        		 iconCls:'icon-delete',
        		 tooltip: '删除', 
        		 handler: function(grid, rowIndex, colIndex) {
        			 gridStore.removeAt(rowIndex);
        		 }
        	}]
        }];
		var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
	        clicksToEdit: 1
	    });
		var row_2=Ext.create('Ext.grid.Panel', {
			id:'familyMemberGridPanel',
			region : 'south',
			//title:"家庭（成员）情况",
			minHeight:100,
			columnLines: true,
	        viewConfig: {
	            stripeRows: true
	        },
			store : gridStore,
			columns : columns,
			plugins: [cellEditing],
			tbar:[{text:'新增',iconCls:'icon-add',
				handler:function(){
				    Ext.define('Record', { 
			            extend: 'Ext.data.Model', 
				    }); 
				    var record  = new Record(); 
				    gridStore.insert(0, record);
//				    cellEditing.startEditByPosition({
//				        row: 0, 
//				    	column: 0
//				    });
			}
			}
			]
		});
		var items=[row_2];
		var initConfigg = {
		        title:"家庭（成员）情况",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.payDeposit.add.zhuzhaiPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		reCurrentlyPropertyStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
		
		var reCurrentlyAreaStoreList = [
					                         {"value":"1","text":"50㎡以下"},
					                         {"value":"2","text":"50-70㎡"},
					                         {"value":"3","text":"70-90㎡"},
					                         {"value":"4","text":"90-120㎡"},
					                         {"value":"5","text":"120-140㎡"},
					                         {"value":"6","text":"140-160㎡"},
					                         {"value":"7","text":"160-180㎡"},
					                         {"value":"8","text":"180-200㎡"},
					                         {"value":"9","text":"200㎡以上"}
					                         ];
		var reCurrentlyAreaStore = Ext.data.Store({
				autoDestroy: true,
				fields :["value","text"],
				data : reCurrentlyAreaStoreList
		});
		reCurrentlyStructureStore = new Ext.data.Store({
	    	        singleton:true,
	    	        autoDestroy:true,
	    	        fields: ["id", "codeName"],
	    	        proxy:{
	    	            type:'ajax',
	    	            url:contextPath+'/system/baseCodeValue/getCodeNameByType',
	    	            reader:{
	                        type: 'json', 
	                        root: 'root'  //数据
	                   }
	    	        },
	    	        autoLoad:false
	    });
/*		var reCurrentlyHouseStoreList = [
					                         {"value":"1","text":"安置房"},
					                         {"value":"2","text":"自建房"},
					                         {"value":"3","text":"租房"},
					                         {"value":"4","text":"单位分房"},
					                         {"value":"5","text":"07年前老商品房"},
					                         {"value":"6","text":"07年后老商品房"},
					                         {"value":"7","text":"近百年来房子"},
					                         {"value":"8","text":"其他"}
					                         ];*/
		reCurrentlyHouseStore = new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
   });
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
		                xtype:'numberfield',
		                fieldLabel: '本地购房次数',
		                name: 'reLocalPurchase',
		                id:'reLocalPurchase',
		                maxLength:2,
		                hideTrigger:true,
			             regex:/^[1-9]\d*$/
		            }, {
	            		xtype:'numberfield',
		                fieldLabel:'目前家庭持有住宅数',
		                name:'reCurrentHoldings',
		                id:'reCurrentHoldings',
		                hideTrigger:true,
		                maxLength:2,
			             regex:/^[1-9]\d*$/
		            }, {
			            xtype:'combobox',  
			            id:'reCurrentlyArea',  
			            store: reCurrentlyAreaStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'目前居住的面积',
			            typeAhead: true,
		    			name:'reCurrentlyArea',
		                typeAhead:false, 
		                editable:false
		            }, {
			            xtype:'combobox',  
			            id:'reCurrentlyHouse',  
			            store: reCurrentlyHouseStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'目前居住/办公的房子属性',
			            typeAhead: true,
		    			name:'reCurrentlyHouse',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }]
		        }, {
		            items: [{
		                xtype:'numberfield',
		                fieldLabel: '目前家庭住宅已按揭数',
		                name: 'reResidentialMortgage',
		                id:"reResidentialMortgage",
		                maxLength:3,
		                hideTrigger:true,
			             regex:/^[1-9]\d*$/
		            },{
			            xtype:'combobox',  
			            id:'reCurrentlyProperty',  
			            store: reCurrentlyPropertyStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'目前居住的物业类型',
			            typeAhead: true,
		    			name:'reCurrentlyProperty',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            },{
			            xtype:'combobox',  
			            id:'reCurrentlyStructure',  
			            store: reCurrentlyStructureStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'目前居住的户型结构',  
			            typeAhead: true,
		    			name:'reCurrentlyStructure',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"家庭住宅情况",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,  
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});
Ext.define('customer.payDeposit.add.payDepositPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var coContactTimeStoreList = [
				                         {"value":"1","text":"早上8:30-11:30"},
				                         {"value":"2","text":"下午14:30-17:30"},
				                         {"value":"3","text":"晚上18:30-20:30"}
				                         ];
		var coContactTimeStore = Ext.data.Store({
			    autoDestroy: true,
			    fields :["value","text"],
			    data : coContactTimeStoreList
		});
		var coInformationDaysStoreList = [
				                         {"value":"1","text":"电话"},
				                         {"value":"2","text":"短信"},
				                         {"value":"3","text":"邮件"},
				                         {"value":"4","text":"其他"}
				                         ];
		var coInformationDaysStore = Ext.data.Store({
			    autoDestroy: true,
			    fields :["value","text"],
			    data : coInformationDaysStoreList
		});
		var coContactWeekendStoreList = [
				                         {"value":"1","text":"早上8:30-11:30"},
				                         {"value":"2","text":"下午14:30-17:30"},
				                         {"value":"3","text":"晚上18:30-20:30"}
				                         ];
		var coContactWeekendStore = Ext.data.Store({
			    autoDestroy: true,
			    fields :["value","text"],
			    data : coContactWeekendStoreList
		});
/*		var coWeekendInformationStoreList = [
				                         {"value":"1","text":"电话"},
				                         {"value":"2","text":"短信"},
				                         {"value":"3","text":"邮件"},
				                         {"value":"4","text":"其他"}
				                         ];*/
		coWeekendInformationStore = new Ext.data.Store({
            singleton:true,
            autoDestroy:true,
            fields: ["id", "codeName"],
            proxy:{
                type:'ajax',
                url:contextPath+'/system/baseCodeValue/getCodeNameByType',
                reader:{
                    type: 'json', 
                    root: 'root'  //数据
               }
            },
            autoLoad:false
       });
		var row_1={
				fieldDefaults: {
			            labelAlign: 'left',
			            msgTarget: 'side'
			    },
			    border: false,
			    defaults: {
			            border: false,
			            xtype: 'panel',
			            flex: 1,
			            layout: 'anchor'
			    },
				layout: 'hbox',
				items: [{
		            items: [{
			            xtype:'combobox',  
			            id:'coContactTime',  
			            store: coContactTimeStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'工作日联系时间',
			            typeAhead: true,
		    			name:'coContactTime',
		                typeAhead:false, 
		                editable:false
		            }, {
			            xtype:'combobox',  
			            id:'coInformationDays',  
			            store: coWeekendInformationStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'工作日联系方式', 
			            typeAhead: true,
		    			name:'coInformationDays',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }, {
		                xtype:'textarea',
		                fieldLabel: '备注',
		                anchor: '80%',
		                name:'remark'
		            }]
		        }, {
		            items: [{
			            xtype:'combobox',  
			            id:'coContactWeekend',  
			            store: coContactWeekendStore,
			            displayField: "text",           
			            valueField: "value",  
			            fieldLabel:'周末联系时间',
			            typeAhead: true,
		    			name:'coContactWeekend',
		                typeAhead:false, 
		                editable:false
		            },{
			            xtype:'combobox',  
			            id:'coWeekendInformation',  
			            store: coWeekendInformationStore,
			            displayField: "codeName",           
			            valueField: "id",  
			            fieldLabel:'周末联系方式', 
			            typeAhead: true,
		    			name:'coWeekendInformation',
		                typeAhead:false, 
		                editable:false,
		                queryMode:'local'
		            }]
		        }]
	    };
		var items=[row_1];
		var initConfigg = {
		        title:"联系信息",
		        minHeight:100,
		        fieldDefaults: {
		            labelAlign: 'left',
		            msgTarget: 'side',
		            margin: 5,  
		            width:300
		        },
		        items:items
		};
		Ext.apply(this,initConfigg);
		this.callParent(arguments);
	}
});

Ext.define('customer.payDeposit.addPanel',{
	extend : 'Ext.form.Panel',
	initComponent:function(){
		var estatePanel= Ext.create("customer.payDeposit.add.estatePanel");
		var customerPanel= Ext.create("customer.payDeposit.add.customerPanel");
		var payDepositPanel= Ext.create("customer.payDeposit.add.payDepositPanel");
		var jiatingPanel= Ext.create("customer.payDeposit.add.jiatingPanel",{id:"familyMember"});
		var zhuzhaiPanel= Ext.create("customer.payDeposit.add.zhuzhaiPanel");
		var firstjiePanel= Ext.create("customer.payDeposit.add.firstjiePanel");
		var membergePanel= Ext.create("customer.payDeposit.add.membergePanel");
		
		estatePanel.getForm().findField("customerPhone").setValue(customerPhone);
		// 首次接触时间不可编辑
        firstjiePanel.getForm().findField("ftContactTimes").setValue(Ext.Date.format(new Date(),'Y-m-d'));

		var defaultConfigg = {
				buttonAlign:'center',
				id:'allFormPanel',
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true,  //可以折叠
		        },
		        renderTo:Ext.getBody(),
				items:[estatePanel,customerPanel,firstjiePanel,membergePanel,jiatingPanel,zhuzhaiPanel,payDepositPanel],
				buttons:[
				         {xtype: "button",text: "保存",id:"customerSubmitBtn",iconCls:'icon-save',handler: function(){
//				           	var estate=estatePanel.getForm().getValues();
//				           	var customer=customerPanel.getForm().getValues();
//				           	var payDeposit=payDepositPanel.getForm().getValues();
//				           	var zhuzhai=zhuzhaiPanel.getForm().getValues();
//				           	var firstjie=firstjiePanel.getForm().getValues();
//				           	var memberge=membergePanel.getForm().getValues();
				       /* 	var fromPanel =  Ext.create('Ext.form.FormPanel',{
					     	       renderTo:Ext.getBody(),
					     		   frame: true,
					     	       collapsible: false,
					     	       autoScroll:false,
					     		   defaultType : 'textfield',
					     		   defaults : {
					     			   anchor : '100%',
					     		   },
					     		   fieldDefaults : {
					     			   flex : 1
					     		   },
					     		   items:[estatePanel,customerPanel,payDepositPanel,zhuzhaiPanel,firstjiePanel,membergePanel]
					     	});*/

				        	 var flag = true;
                             var projectSelect = Ext.getCmp('cbstore').getValue();
                             if(projectSelect == null || projectSelect == '' || projectSelect === undefined){
                                 layer.open({
                                     title:'客户信息完善',
                                     content:'\<span\ style="color:#c00">请先选择“项目名称”，“项目名称”必填\<\/span\>',
                                     btn:'继续填写',
                                     yes:function(index){
                                         layer.close(index);
                                         flag=false;
                                     }
                                 });
                                 return;
                             }

			            		var customerPhone = Ext.getCmp('customerPhone').getValue();
			            		if(customerPhone){
			            			var projectId = Ext.getCmp('cbstore').getValue();
			            			Ext.Ajax.request({
			            				url: contextPath+'/customer/customer/customerPhone',
			            				params: {
			            					phone: customerPhone,
			            					projectId:projectId
			            				},
			            				method: 'POST',
			            				success: function(response){
			            					var text = Ext.decode(response.responseText);
			            					if(text.res=="1"){
			            						Ext.MessageBox.alert('提示', '该手机号码已存在!');
			            						flag=false;
			            						return;
			            					}else if(text.res=="10000"){
			            						Ext.MessageBox.alert("系统提示","系统异常!");
			            						flag=false;
			            						return;
			            					}
			            				}
			            			}); 
			            			var peMobile = Ext.getCmp('peMobile').getValue();
			            			if(customerPhone == peMobile){
			            				Ext.MessageBox.alert('提示', '联系号码与手机号码重复');
	            						flag=false;
	            						return;
			            			}
			            		}

								if(customerPhone == null || customerPhone == '' || customerPhone === undefined){
                                    layer.open({
                                        title:'客户信息完善',
                                        content:'\<span\ style="color:#c00">请先填写“联系电话”，“联系电话”必填\<\/span\>',
                                        btn:'继续填写',
                                        yes:function(index){
                                            layer.close(index);
                                            flag=false;
                                        }
                                    });
                                    return;
								}

					     	var form = Ext.getCmp("allFormPanel").getForm();
//					     	console.log(form);
//		             		var index = cbstore.find('projectName',form.getValues().projectId);
//		             		alert(cbstore.getAt(index).data.id);
//					     	form.getValues().projectId = cbstore.getAt(index).data.id;
//					     	alert(form.getValues().projectId);
				           	if(form.isValid()){
				           		var jsonArray=[];
				           		var jsonArray2=[];
				           		var jsonArray3=[];
				           		var jsonArray4=[];
				           		var resultJson="";
				           		var resultJson2="";
				           		var resultJson3="";
				           		var resultJson4="";
				           		//获得客户等级
				           		//意向户型
				           		var customerStar = Ext.getCmp('customerStar').getValue();
				           		if(customerStar=="1"||customerStar=="2"||customerStar=="3"){
						     		var records2=gridStore2.getCount();
//						     		if(records2<=0){
//						     			Ext.Msg.alert('提示', '关注户型不足,无法新增客户!');
//						     			flag=false;
//						     		}
						     		if(records2>0){
						     			for(var i=0;i<records2;i++){
							     			jsonArray2.push(Ext.JSON.encode(gridStore2.getAt(i).data));
							     		}
							     		 resultJson2=Ext.JSON.encode(jsonArray2);
						     		}
						     		
				           		}
				           		var records3=gridStore3.getCount();
				           		var records4=gridStore4.getCount();
							/* 修改必填项之后 这两个将 改为非必填
				           		if(customerStar=="1"||customerStar=="2"){
				           			if(records3<=0){
						     			Ext.Msg.alert('提示', '请选择意向组团!');
						     			return;
						     		}
						     		if(records4<=0){
						     			Ext.Msg.alert('提示', '请选择意向房源！');
						     			return;
						     		}
						     		
				           		}
				           		*/
				           		for(var i=0;i<records4;i++){
					     			jsonArray4.push(Ext.JSON.encode(gridStore4.getAt(i).data));
					     		}
					     	    resultJson4=Ext.JSON.encode(jsonArray4);
					     	    
					     		if(records3>0){
					     			for(var i=0;i<records3;i++){
						     			jsonArray3.push(Ext.JSON.encode(gridStore3.getAt(i).data));
						     		}
						     		 resultJson3=Ext.JSON.encode(jsonArray3);
					     		}
					     		var records=gridStore.getCount();
					     		if(records>0){
					     			for(var i=0;i<records;i++){
						     			jsonArray.push(Ext.JSON.encode(gridStore.getAt(i).data));
						     		}
						     		resultJson=Ext.JSON.encode(jsonArray);
					     		}
								//客户等级验证 2017.7.18
                                var level = validUserLevel();

                                var params = form.getValues();

                                params.isIntentionIntact = '1';

                                if(level == -1){// 验证不通过
                                    if(params.intentionLevel === undefined || params.intentionLevel == null ||params.intentionLevel == ''){
                                        params.intentionLevel = realLevel();
									}
                                    layer.confirm('填写信息不全，不满足意向等级【'+levels[params.intentionLevel]+'】要求；',{
                                        btn:['我要保存','继续填写']
                                    },function(index){
                                        layer.close(index);
                                        layer.open({
                                            title:'客户信息完善',
                                            type: 1,
                                            area: ['450px', '300px'],
                                            shadeClose: true, //点击遮罩关闭
                                            content: '\<\div style="padding:5px;">填写信息不全，不满足意向等级【'+levels[params.intentionLevel]+'】要求；\<\/div>'+
                                            '\<\div style="margin:5px;"> 继续保存客户为意向等级【'+levels[params.intentionLevel]+'】；\<\/div>'+
                                            '\<\div style="margin:5px;"><span>备注：</span><textarea style="width: 400px;height: 100px;" id="remarkid" class="layui-layer-input"></textarea>\<\/div>',
                                            btn:['我要保存','按实际意向等级保存']
                                            ,yes:function(index){
                                                params.intentionLevelRemark = $("#remarkid").val();
                                                if(params.intentionLevelRemark == '' || params.intentionLevelRemark == null){
                                                    layer.tips('备注不能为空', '#remarkid');
                                                    return;
                                                }
                                                params.isIntentionIntact = '0';//信息不匹配意向登记
                                                add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                                layer.close(index);
                                            },btn2:function(){
                                                //计算实际level
                                                params.intentionLevel = realLevel();
                                                add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                            }});

                                    },function(index){
                                        layer.close(index);
                                    })
                                }else if(level == 0){//验证通过
                                    add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                }else{//自动判断意向等级()
                                    params.intentionLevel = realLevel();
                                    //若意向等级为5的判断 是否满足字段
									if(params.intentionLevel == '5'){
										if(notBlank(DCouple)){
											params.isIntentionIntact = '1';//信息匹配意向等级
										}else{
											params.isIntentionIntact = '0';//信息不匹配意向等级
										}
                                    }

                                    add(params,resultJson,resultJson2,resultJson3,resultJson4);
                                }



// 					     		if(flag){
// 					     			Ext.getCmp("customerSubmitBtn").setVisible(false);
// 					     			Ext.Ajax.request({
// 					     				url: contextPath+'/customer/customer/add?gridJson='+resultJson+'&gridJson2='+resultJson2+'&gridJson3='+resultJson3+'&gridJson4='+resultJson4,
// 					     				params:form.getValues(),
// 					     				callback: function (options, success, response) {
// 					     					 if (success) {
// 					     						 var obj = JSON.parse(response.responseText);
// 					     						 if(obj.res=="1"){
// 					     							Ext.MessageBox.alert("系统提示","保存成功");
// 					     							setTimeout(function(){
// 					     								location.href=contextPath+'/customer/customer/index?menu=menu_0006_0001';
// 					     								//location.href=contextPath + "/customer/customer/toDetail?customerId="+obj.obj+"&resourcesCode=menu_0006_0001";
// 					     							}, 2000)
// //					     							Ext.getCmp("save_button").setVisible(false);
// 					     						 }else{
// 					     							Ext.getCmp("customerSubmitBtn").setVisible(true);
// 					     							 Ext.MessageBox.alert("系统提示",obj.resMsg);
// 					     						 }
// 					     		        	 }else{
// 					     		        		Ext.getCmp("customerSubmitBtn").setVisible(true);
// 					     		        		 Ext.MessageBox.alert("系统提示","系统异常!");
// 					     		        	 }
// 					     				}
//
// 					     			});
// 					     		}
					        	 
					         }
				         }
				         },
//				         {xtype: "button",text: "提交审核",iconCls:'icon-save',handler: function(){
//				        	 
//				         }},
				         {xtype: "button",text: "返回",iconCls:'icon-save',handler: function(){
				        	 location.href=contextPath+'/customer/customer/index?menu=menu_0006_0001';
				         }}
				]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
	}
});


